<?php
/*
 * 支付回调类
 */

class Payment_Alipay_Notify 
{
    public function Handle ($status = false)
    {
        $pay  = PaySDK::instance('alipay');
        $data = $pay->verify_notify();


        if ($data === false)
        {
            return FALSE;
        }

        $orderNo       = Arr::get($data, 'out_trade_no');
        $transactionId = Arr::get($data, 'transaction_id', NULL);
        $merchantId    = NULL;
        $resultCode    = 'SUCC';//$data['trade_status'];
        $returnCode    = 'SUCC';//$data['trade_status'];

        $trans = Payment_Transaction::instanceByOutTradeNo ($orderNo);
        if ($trans)
        {
            $trans->notify_paid ('ALIPAY', $transactionId, $merchantId, $resultCode, $returnCode);
		    return true;
        }
        else
        {
            Kohana::$log->add(Log::DEBUG, print_r($data, TRUE));
            return false;
        }

	}
}
